package com.mygame.Svetofor.activities;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.mygame.Svetofor.ProfileManager;
import com.mygame.Svetofor.R;
import com.mygame.Svetofor.db.ProfileSQL;

public class MainActivity extends Activity {
    /**
     * Called when the activity is first created.
     */
    private Activity me = this;
    private TextView username;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Button startGame = (Button) findViewById(R.id.start_game);
        Button profile = (Button) findViewById(R.id.profile);
        Button score = (Button) findViewById(R.id.score_btn);
        Button settings = (Button) findViewById(R.id.settings);
        Button exit = (Button) findViewById(R.id.exit);
        username = (TextView) findViewById(R.id.user_name);

        ProfileManager.fileName = getFilesDir() + "/profiles.txt";
        ProfileManager.INSTANCE.setProfileSQL(new ProfileSQL(getApplicationContext()));
        ProfileManager.INSTANCE.loadProfiles();

        updateProfile();

        startGame.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Intent intent = new Intent(me, GameActivity.class);
                startActivity(intent);
            }
        });

        profile.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Intent intent = new Intent(me, ProfileActivity.class);
                startActivity(intent);
            }
        });

        score.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Intent intent = new Intent(me, ScoreActivity.class);
                startActivity(intent);
            }
        });

        settings.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Intent intent = new Intent(me, SettingsActivity.class);
                startActivity(intent);
            }
        });

        exit.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                System.exit(0);
            }
        });

    }

    @Override
    public void onResume () {
        super.onResume();
        updateProfile();
    }

    private void updateProfile() {
        username.setText(ProfileManager.INSTANCE.getCurrentProfile().getName());
    }
}
